package org.geotools.tutorial.quickstart.UI;

import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.tutorial.quickstart.Utilities.FeatureSourceTableModel;
import org.geotools.tutorial.quickstart.Utilities.GridBagConstraintsHelper;

import javax.swing.*;
import java.awt.*;

/**
 * @author
 * @DesktopJavaDocable disable
 */
public class DialogAttributeTable extends JDialog {
	private JTable table;
	private SimpleFeatureCollection simpleFeatureCollection;
	protected transient DialogResult dialogResult = DialogResult.NO;

	public DialogAttributeTable(Frame owner, String title, SimpleFeatureCollection simpleFeatureCollection) {
		super(owner, title);
		this.simpleFeatureCollection = simpleFeatureCollection;
		initLayout();
	}

	private void initLayout() {
		this.table = new JTable();
		this.table.setModel(new FeatureSourceTableModel(this.simpleFeatureCollection));
		JScrollPane jScrollPane = new JScrollPane(this.table);
		this.setLayout(new GridBagLayout());
		this.add(jScrollPane, new GridBagConstraintsHelper(0, 0, 1, 1).setWeight(1, 1).setFill(GridBagConstraints.BOTH).setAnchor(GridBagConstraints.CENTER).setInsets(10, 10, 10, 10));
	}

	public DialogResult getDialogResult() {
		return this.dialogResult;
	}

	public DialogResult showDialog() {
		try {
			setSize(1250, 900);
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return this.getDialogResult();
	}

	public enum DialogResult {
		OK,
		CANCEL,
		NO,
	}
}
